package com.kernel.net;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;

/****************************************
 * @name HelloClient
 * @description
 * @author 黄彬恒
 * @since 2018/8/24
 ***************************************/
public class EchoClient {
    public static void main(String[] args) throws IOException {
        Socket client = null;// 表示客户端
        client = new Socket("127.0.0.1", 8888);
        BufferedReader input = null;//接收键盘数据
        PrintStream out = null;// 发送数据
        BufferedReader buf = null;// 一次性接收完成
        input = new BufferedReader(new InputStreamReader(System.in));
        buf = new BufferedReader(new InputStreamReader(client.getInputStream()));
        out = new PrintStream(client.getOutputStream());
        boolean flag = true;
        while (flag) {
            System.out.println("输入信息:");
            String str = input.readLine();// 接收键盘的输入信息
            out.println(str);// 发送客户端数据
            if ("bye".equals(str)) {
                flag = false;
            } else {
                String eho = buf.readLine();
                System.out.println(eho);
            }
        }
        buf.close();
        client.close();
    }
}
